package com.xingjibase.activity

import android.app.Application
import android.os.Bundle
import com.activitys.BaseActivity
import com.alibaba.android.arouter.launcher.ARouter
import com.clj.fastble.BleManager
import com.clj.fastble.scan.BleScanRuleConfig
import com.uuzuche.lib_zxing.activity.ZXingLibrary

/**
 * 控件注册放在activity中
 * 增加Application的启动速度
 * 减少初次启动时，首帧的白屏等待时间
 */
open class ActivityInit : BaseActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        if (!MyApp.isInitStatu()) {
            ZXingLibrary.initDisplayOpinion(MyApp.context)

            ARouter.openLog()
            ARouter.openDebug()
            ARouter.init(MyApp.context as Application?)
            configBle(MyApp.context as Application)
            MyApp.setInitStatu(true)
        }
    }

    /**
     * 蓝牙配置
     *
     * @param app
     */
    private fun configBle(app: Application) {
        BleManager.getInstance().init(app)
        BleManager.getInstance().enableLog(true)

        BleManager.getInstance()
            .enableLog(true)
            .setReConnectCount(1, 5000)
            .setSplitWriteNum(20)
            .setConnectOverTime(10000).operateTimeout = 5000

        val config = BleScanRuleConfig.Builder()
            .setScanTimeOut(3000)
            .build()
        BleManager.getInstance().initScanRule(config)
    }
}